<template>
  <div class="UserCenter">
    <!-- hhh -->
    <div class="container">
      <div class="leftMenu">
        <LeftMenu />
      </div>
      <div class="content">
        <router-view />

      </div>
    </div>
  </div>
</template>

<script>
import LeftMenu from './leftMenu/LeftMenu.vue'

import { mapGetters } from 'vuex'
export default {
  components: {
    LeftMenu
  },
  methods: {
    checkLogin() {
      if (!this.getIsLogin) {
        this.$router.push('/front/home')
      }
    }
  },
  computed: {
    ...mapGetters(['getUserData','getIsLogin'])
  },
  watch: {
    getIsLogin(v1, v2) {

      this.checkLogin()
    }
  },
  created() {
    // 开始的时候，判断登录
    // this.checkLogin()
    this.$show.$emit('getLogin')
    // 会发射请求登录的要求
    this.$show.$on('getUserLoginSuccess', this.checkLogin)
  },
  // beforeRouteLeave(){

  // },
  beforeDestroy(){
    this.$show.$off('getUserLoginSuccess')
  }
}
</script>

<style scoped>
.UserCenter {
  background-color: #f0f3ef;
  padding: 20px 0;
}
.container {
  display: flex;
  height: calc(100vh - 80px);
}

.leftMenu {
  width: 180px;
  height: 100%;
  background-color: #fff;
  margin-bottom: 20px;
  margin-right: 20px;
  padding: 10px 10px;
}
.content {
  flex: 1;
  height: 100%;
  background-color: #fff;
  overflow-y: scroll;

  /* padding: 20px; */
  /* background-color: red; */
}
</style>
